<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
		
	</style>
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">
		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item" style="margin-bottom: 5px;">
					<div class="layui-inline">
						<div class="layui-input-inline">
							<select name="acc_id" lay-search="" autocomplete="off">
								<option value="" >直接选择充值帐户</option>
								{volist name="acc_list" id="vo"}
									<option value="{$vo.id}" >{$vo.name_id}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<div class="layui-input-inline">
							<select name="cu_id" lay-search="" autocomplete="off">
								<option value="" >直接选择客户名称</option>
								{volist name="cu_list" id="vo"}
									<option value="{$vo.id}" >{$vo.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<div class="layui-input-inline">
							<select name="channel_id" lay-search="" autocomplete="off">
								<option value="" >直接选择端口</option>
								{volist name="arr.channel" id="vo"}
									<option value="{$vo.id}" >{$vo.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<div class="layui-input-inline">
							<select name="industry_id" lay-search="" autocomplete="off">
								<option value="" >直接选择行业</option>
								{volist name="arr.industry" id="vo"}
									<option value="{$vo.id}" >{$vo.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<div class="layui-input-inline">
							<select name="items_id" lay-search="" autocomplete="off">
								<option value="" >直接选择项目名称</option>
								{volist name="arr.items" id="vo"}
									<option value="{$vo.id}" >{$vo.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<div class="layui-input-inline">
							<select name="media_id" lay-search="" autocomplete="off">
								<option value="" >直接选择媒介名称</option>
								{volist name="m_list" id="vo"}
									<option value="{$vo.id}" >{$vo.username}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<div class="layui-input-inline">
							<input type="text" name="time" id="date" placeholder="请选择时间" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
					</div>
				</div>
			</form>
		</fieldset>

		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

		<script type="text/html" id="currentTableBar">
			<a style="{{d.status==-1?'display:none':''}}{{d.status == 1?'display:none;':''}}" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="cashier">出纳</a>
			<a style="{{d.status==-1?'display:none':''}}{{d.status == 1?'display:none;':''}}" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">驳回</a>
			<a style="{{d.status == 1?'':'display:none;'}}" class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="rollback">回滚</a>
		</script>
		<script type="text/html" id="wxmsg">
			<a class="layui-btn layui-btn-xs data-count-edit btn" lay-event="wxmsg">复制</a>
		</script>
		<script type="text/html" id="statusTable">
			<span onmouseover=get_msg(this) data-msg="{{d.reject}}"  style="color: red;font-weight: bold;{{d.status == -1?'':'display:none;'}}">驳回</span>
			<span  style="color: #03A9F4;font-weight: bold;{{d.status == 0?'':'display:none;'}}">审核中</span>
			<span  style="color: #4CAF50;font-weight: bold;{{d.status == 1?'':'display:none;'}}">完成</span>
		</script>
		<script type="text/html" id="fansTable">
			<span style="{{d.is_fans==0?'':'display:none'}}" class="layui-badge layui-bg-gray">否</span>
			<span style="{{d.is_fans>=1?'':'display:none'}}" class="layui-badge">是</span>
		</script>
	</div>
</div>
<script src="__static/js/clipboard/clipboard.min.js" charset="utf-8"></script>
<script>
function get_msg(obj){
	var str = $(obj).attr('data-msg');
	layer.tips(str,$(obj));
}
//驳回
function get_bohui(id){
	layer.prompt({
	  formType: 2,
	  title: '驳回原因',
	  area: ['350px', '150px'] //自定义文本域宽高
	}, function(value, index, elem){
		get_add_reject(id,value);
	});
}
//提交驳回
function get_add_reject(id,reject){
	var in2 = layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
	  $.post("{:url('reject')}?t=json",{id:id,reject:reject},function(da){
		  layer.closeAll();
		  if(da['code'] == 1){
			  //重载数据表格
			  get_apply(da['msg']);
		  }else{
			  layer.msg(da['msg'], { icon : 5 });
		  }
	  });
}

//出纳确认
function get_cashier(id){
	layer.open({
        type: 2,
        title:'出纳确认',
        area: ['50%', '50%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('audit')}?id="+id 
    });
    //layer.full(index);
} 
//回滚
function get_rollback(id){
	layer.confirm('你确认要回滚吗？', function(index){
		var in2 = layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
		$.post("{:url('rollback')}?t=json",{id:id},function(da){
			layer.closeAll();
			if(da['code'] == 1){
		  		//重载数据表格
		  		get_apply(da['msg']);
		 	}else{
		  		layer.msg(da['msg'], { icon : 5 });
		 	}
		});
	});       
		      
	
}


	var form,table,laydate
	layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
		$ = layui.jquery , form = layui.form , table = layui.table , laydate = layui.laydate
		laydate.render({
		    elem: '#date' //指定元素
			,range: '&'
		  });
		table.render({
			elem: '#currentTableId',
			height: 'full-150',
			id:'acc_re_info',
			url: '{:url("finance/account_recharge", ["t"=>"json"])}',
			method : 'post',
			toolbar: true,
			totalRow: true,
			cols: [[
				{ field: 'name_id', title: '账户ID' ,width:160,fixed: 'left',templet:function(d){
					
					return d.channel_name == '知乎'?d.name_id+' / '+d.acc_name : d.name_id
				}},
				{ field: 'create_time', title: '申请时间' ,width:180,fixed: 'left'},
				{ field: 'channel_name', title: '端口',width:100 },
				
				{ field: 'hy_name', title: '行业' ,width:100},
				{ field: 'item_name', title: '项目名称' ,width:100},
				{ field: 'client_name', title: '客户名称',width:100},
				
				{ field: 'id', title: '端口/销售/客户',width:160,templet:function(d){
					var s = d.channel_rebate == undefined ?0:d.channel_rebate
					return s+' / '+d.sell_rebates+' / '+d.rebate
				}},
			
				{ field: 'currency', title: '实充帐户币',width:120, totalRow: true},
				// { field: 'refund', title: '已退帐户币',width:120, totalRow: true},
				{ field: 'amount', title: '客户金额(元)',width:110, totalRow: true},
				{ field: 'channel_money', title: '端口金额(元)',width:110, totalRow: true},
				{ field: 'profit', title: '公司利润(元)',width:110, totalRow: true},
				{ field: 'sell_profit', title: '销售利润',width:100, totalRow: true },
				{ field: 'send_num', title: '群消息', toolbar: '#wxmsg', width:100 },
				{ field: 'status', title: '状态',toolbar:'#statusTable',width:100 },
				{ field: 'audit_proof_url', title: '财务凭证',width:100,templet:function(d){
					return d.audit_proof_url?'<img src="'+d.audit_proof_url+'">':''
				}},
				{ field: 'note', title: '备注' ,width:200},
				{ field: 'media_name', title: '媒介',width:180},
				
				{ field: 'code', title: '编号',width:180, totalRowText: '合计'},
				{ title: '操作',fixed: 'right', toolbar: '#currentTableBar', align: "center",width:180 }
			]],
			
			limit: 30,
			page: true,
			skin: 'line',
			
		});

		//监听操作栏事件
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'cashier':
					get_cashier(data.id);
				break;
				case 'delete':
					get_bohui(data.id);
				break;
				case 'rollback':
					get_rollback(data.id);
				break;
				case 'wxmsg':
					//console.log(data);
					var str12 = '账户：'+data.name_id+' \n充值：'+data.currency+'币';
					new Clipboard('.btn', {
						text: function(trigger) {
							layer.msg('复制成功', {icon: 6});
							return str12;
						}
					});
				break;
			}
			
		});
		//监听行单击事件
		table.on('row(currentTableFilter)', function(obj){
			  layer.photos({
				  photos: obj.tr
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
				});
			});
		
		
		//搜索
		form.on('submit(data-search-btn)', function(data){
			var articleFrom = data.field;
			table.reload('acc_re_info', {
			  	url: '{:url("finance/account_recharge", ["t"=>"json"])}',
				where:articleFrom
			});
			return false;
		  });
	});
	//重载数据表
	function get_apply(msg){
		table.reload('acc_re_info', {
			  url: '{:url("finance/account_recharge", ["t"=>"json"])}',
			});
		layer.msg(msg, {icon: 6});
	}
</script>

</body>
</html>